bitkeeper revision 1.1041.1.6 (40e3e568dXMUca5bKVlAd9SLsmVpEw)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Thu, 1 Jul 2004 10:20:24 +0000 (10:20 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Thu, 1 Jul 2004 10:20:24 +0000 (10:20 +0000)
Release the channel and port when a domain is destroyed.
Allows the domain to finally go away.

tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/SrvDaemon.py
tools/python/xen/xend/server/channel.py

index e3e4e92cbd7dba4bda22265e28593a8d61ed08a1..c0de8fed012fcb6016f376addc84e7b92bb46d5f 100644 (file)
@@ -504,6 +504,9 @@ class XendDomainInfo:
         devices have been released.
         """
         if self.dom is None: return 0
+        chan = xend.getDomChannel(self.dom)
+        if chan:
+            chan.close()
         return xc.domain_destroy(dom=self.dom)
 
     def cleanup(self):
index 7dde51f68fad249e56f94e91e4ac239473b095d8..63c4dd1bee49438fa9b05e3435a01b063e402ed6 100644 (file)
@@ -663,6 +663,15 @@ class Daemon:
         reactor.diconnectAll()
         sys.exit(0)
 
+    def getDomChannel(self, dom):
+        """Get the channel to a domain.
+
+        dom domain
+
+        returns channel (or None)
+        """
+        return self.channelF.getDomChannel(dom)
+
     def blkif_set_control_domain(self, dom, recreate=0):
         """Set the block device backend control domain.
         """
index ecd9cf93f35be74a47fae2b413c4e83aac65a06b..da19d621c2556eb0ecc7197d4f2c527a27427ad7 100755 (executable)
@@ -48,15 +48,31 @@ class ChannelFactory:
     def domChannel(self, dom):
         """Get the channel for the given domain.
         Construct if necessary.
+
+        dom domain
+
+        returns channel
+        """
+        chan = self.getDomChannel(dom)
+        if not chan:
+            chan = Channel(self, dom)
+            self.addChannel(chan)
+        return chan
+
+    def getDomChannel(self, dom):
+        """Get the channel for the given domain.
+
+        dom domain
+
+        returns channel (or None)
         """
         dom = int(dom)
         for chan in self.channels.values():
             if not isinstance(chan, Channel): continue
             if chan.dom == dom:
                 return chan
-        chan = Channel(self, dom)
-        self.addChannel(chan)
-        return chan
+        return None
+        
 
     def virqChannel(self, virq):
         """Get the channel for the given virq.
@@ -109,12 +125,11 @@ class BaseChannel:
 
     def notificationReceived(self):
         """Called when a notification is received.
-        Closes the channel on error, otherwise calls
-        handleNotification(type), which should be defined
+        Calls handleNotification(), which should be defined
         in a subclass.
         """
-        if not self.closed:
-            self.handleNotification(type)
+        if self.closed: return
+        self.handleNotification()
 
     def close(self):
         """Close the channel. Calls channelClosed() on the factory.
@@ -122,7 +137,7 @@ class BaseChannel:
         """
         self.factory.channelClosed(self)
 
-    def handleNotification(self, type):
+    def handleNotification(self):
         """Handle notification.
         Define in subclass.
         """
@@ -172,7 +187,7 @@ class VirqChannel(BaseChannel):
         """
         self.clients.append(client)
 
-    def handleNotification(self, type):
+    def handleNotification(self):
         for c in self.clients:
             c.virqReceived(self.virq)
 
@@ -221,13 +236,14 @@ class Channel(BaseChannel):
         """Close the channel. Calls lostChannel() on all its devices and
         channelClosed() on the factory.
         """
+        if self.closed: return
         self.closed = 1
         for d in self.devs:
             d.lostChannel()
         self.factory.channelClosed(self)
         self.devs = []
         self.devs_by_type = {}
-        del self.port
+        self.port.disconnect()
 
     def registerDevice(self, types, dev):
         """Register a device controller.
@@ -271,7 +287,10 @@ class Channel(BaseChannel):
                    self.getLocalPort(),
                    self.getRemotePort()))
 
-    def handleNotification(self, type):
+    def handleNotification(self):
+        if self.closed:
+            print 'handleNotification> Notification on closed channel', self
+            return
         work = 0
         work += self.handleRequests()
         work += self.handleResponses()